package CommonEvent;

import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.touch.offset.PointOption;

import static Utils.MyLogger.logInfo;
/**
 * @author 锄禾
 * @projectName MkPack
 * @description: Monkey点击事件操作类
 */
public class MonkeyTapEvent extends MonkeyEvent{
    private int x,y;
    private AndroidDriver androidDriver;

    public MonkeyTapEvent(AndroidDriver driver, int x, int y){
        super(MonkeyEvent.EVENT_TYPE_TAP);
        this.x = x;
        this.y = y;
        androidDriver = driver;
    }

    /**
    　* @author 锄禾
    　* @description: 点击操作
    　* @param
    　* @return
    　*/
    public int injectEvent() throws Exception{
        try {
            logInfo("Monkey点击事件：点击==>("+ x + "," + y + ")");
            TouchAction touchAction = new TouchAction(androidDriver);
            touchAction.tap(PointOption.point(x,y)).perform();
            logInfo("完成点击事件！");
            return MonkeyEvent.INJECT_SUCCESS;
        }catch (Exception E){
            logInfo(this.getClass().getName() + "-" + "点击事件异常：" + E);
            return INJECT_FIAL;
        }
    }
}
